<template>
  <div class="nav-header">
    <el-icon size="30" @click="handleFoldClick">
      <component :is="isFold ? 'Expand' : 'Fold'"></component>
    </el-icon>
    <div class="content">
      <div>
        <YZNavBreadcrumb :breadcrumbs="breadcrumbs" />
      </div>
      <div>
        <UserInfo />
      </div>
    </div>
  </div>
</template>

<script lang="ts">
import { computed, defineComponent, ref } from 'vue'
import YZNavBreadcrumb from '@/baseUi/NavBreadcrumb'
import { pathMapBreadcrumbs } from 'utils/mapMenus'
import UserInfo from './components/UserInfo.vue'
import { useStore } from 'vuex'
import { useRoute } from 'vue-router'

export default defineComponent({
  components: { UserInfo, YZNavBreadcrumb },
  emits: ['foldChange'],
  setup(props, { emit }) {
    // 定义展开折叠
    const isFold = ref(false)
    // 展开折叠事件
    const handleFoldClick = () => {
      isFold.value = !isFold.value
      emit('foldChange', isFold.value)
    }
    const route = useRoute()
    const store = useStore()

    // 面包屑数据
    const breadcrumbs = computed(() => {
      const currentRoute = route.path
      const userMenus = store.state.login.userMenus
      return pathMapBreadcrumbs(userMenus, currentRoute)
    })

    return {
      isFold,
      breadcrumbs,
      handleFoldClick
    }
  }
})
</script>

<style lang="scss" scoped>
.nav-header {
  width: 100%;
  .el-icon {
    cursor: pointer;
  }
  display: flex;
  align-items: center;
  .content {
    flex: 1;
    padding: 0 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
}
</style>
